//
//  TXWellcomeViewController.swift
//  MicroBlog
//
//  Created by Jokin on 2017/3/30.
//  Copyright © 2017年 jokin. All rights reserved.
//

import UIKit

class TXWellcomeViewController: UIViewController {

    
    private lazy var imageView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    fileprivate lazy var welcomeLabel: UILabel = {
    
        let laebl = UILabel()
        laebl.textColor = UIColor.darkGray
        laebl.font = UIFont.systemFont(ofSize: 15)
        laebl.text = "欢迎回来"
        return laebl
    }()
    
    
    fileprivate lazy var headerImageV: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageV.layer.masksToBounds = true
        imageV.layer.cornerRadius = 45
        return imageV
    }()
    override func loadView() {
        view = imageView
    }

    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        creatUI()
        
        
    }
    
    
    
    
    func creatUI() {
        view.addSubview(headerImageV)
        view.addSubview(welcomeLabel)
        headerImageV.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(200)
            make.size.equalTo(CGSize(width: 90, height: 90))
        }
        
        welcomeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(headerImageV.snp.bottom).offset(10)
            make.centerX.equalTo(headerImageV)
        }
        
        
        
    }
    override func viewDidAppear(_ animated: Bool) {
        startAnimation()
    }

    func startAnimation() {
        welcomeLabel.alpha = 0
        headerImageV.snp.updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
            
        }
        
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: {
            self.view.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1, animations: {
                //  显示label
                self.welcomeLabel.alpha = 1
            }, completion: { (_) in
                print("切换到根视图控制器进入首页")
                //  发送切换根视图的通知
                NotificationCenter.default.post(name: NSNotification.Name(SwitchRootVCNotification), object: nil)
            })

        }
    }
    
    
    
    

}
